#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "tcpmgr.h"
MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    //setCentralWidget的Dialog不要加this，否则有问题。
    _login_dlg = new LoginDialog();
    //当前的CentralWidget会被自动析构
    setCentralWidget(_login_dlg);

    //点注册跳转到注册界面
    connect(_login_dlg,&LoginDialog::switchRegister,this,&MainWindow::SlotSwitchReg);
    //点击忘记密码，跳转到重置
    connect(_login_dlg,&LoginDialog::switchReset,this,&MainWindow::SlotSwitchReset);

    connect(TcpMgr::GetInstance().get(),&TcpMgr::sig_swich_chatdlg,this,&MainWindow::Slot_swich_chatdlg);

    //emit TcpMgr::GetInstance()->sig_swich_chatdlg();
}


void MainWindow::Slot_swich_chatdlg(){
    _chat_dlg = new ChatDialog();
    setCentralWidget(_chat_dlg);
    this->setMinimumSize(QSize(800,600));
    this->setMaximumSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::SlotSwitchReg()
{
    _register_dlg = new registeredDialog();
    connect( _register_dlg, &registeredDialog::sigSwitchLogin, this, &MainWindow::SlotSwitchLogin);
    setCentralWidget(_register_dlg);
}

void MainWindow::SlotSwitchLogin(){
    _login_dlg = new LoginDialog();
    setCentralWidget(_login_dlg);
    connect(_login_dlg,&LoginDialog::switchRegister,this,&MainWindow::SlotSwitchReg);
    connect(_login_dlg,&LoginDialog::switchReset,this,&::MainWindow::SlotSwitchReset);
}

void MainWindow::SlotSwitchReset()
{
    _reset_dlg = new ResetDialog();
    connect(_reset_dlg,&ResetDialog::sigSwitchLogin,this,&MainWindow::SlotSwitchLogin);
    setCentralWidget(_reset_dlg);
}
